package xyz.xtt.asset.service;

import java.math.BigDecimal;
import java.util.List;
import java.util.Set;

import com.baomidou.mybatisplus.extension.service.IService;

import xyz.xtt.asset.api.enums.ReferProtocolEnum;
import xyz.xtt.asset.client.response.AssetAccountResponse;
import xyz.xtt.asset.entity.TblAssetAccount;
import xyz.xtt.asset.entity.TblAssetTransaction;
import xyz.xtt.asset.entity.TblAssetTransactionRecord;
import xyz.xtt.asset.enums.OrderTypeEnum;
import xyz.xtt.asset.enums.TransactionSideEnum;
import xyz.xtt.asset.request.OperateUpRequest;

/**
 * <p>
 * 1155资产关系表 服务类
 * </p>
 *
 * @author author
 * @since 2024-12-25
 */
public interface ITblAssetAccountService extends IService<TblAssetAccount> {
	/**
	 * 人拥有的数量
	 * 
	 * @param assetId
	 * @param userId
	 * @return
	 */
	Long ownNum(Long assetId, Long userId);

	/**
	 * 查用户余额，并加行锁
	 * 
	 * @param assetId
	 * @param userId
	 * @return
	 */
	TblAssetAccount ownerAssetForUpdate(Long assetId, Long userId);

	/**
	 * 查询用户拥有的某资产
	 * 
	 * @param assetId
	 * @param userId
	 * @return
	 */
	TblAssetAccount account(Long assetId, Long userId);

	/**
	 * 查询用户拥有的某资产, 不检查余额
	 * 
	 * @param assetId
	 * @param userId
	 * @return
	 */
	TblAssetAccount accountNoCheckAmount(Long assetId, Long userId);

	/**
	 * 查询用户拥有的某资产, 不检查余额, 如果帐户不存在，会初始化, 但没有余额
	 * 
	 * @param assetId
	 * @param userId
	 * @return
	 */
	TblAssetAccount accountIsNullCreate(Long assetId, Long userId, BigDecimal price);

	/**
	 * 帐户不存在，创建并初始化数量为１
	 * 
	 * 用于721类型的资产
	 * 
	 * @param assetId
	 * @param userId
	 * @return
	 */
	TblAssetAccount accountIsNullCreateAfterInit(Long assetId, Long userId);

	/**
	 * 收户详情
	 * 
	 * @param accountNo
	 * @return
	 */
	TblAssetAccount accountInfo(Long accountNo);

	/**
	 * 拥有的列表
	 * 
	 * @param assetId
	 * @param userId
	 * @return
	 */
	List<TblAssetAccount> ownerList(Long assetId, Long userId);

	/**
	 * 转移
	 * 
	 * @param assetId
	 * @param transactionId
	 * @param from
	 * @param to
	 * @param num
	 */
	void move(List<TblAssetAccount> ownerList, Long transactionId, Long from, Long to, Integer num);

	/**
	 * 划转操作
	 * 
	 * @param buildTransaction
	 * @return
	 */
	Boolean transferFrom(TblAssetTransaction transaction, ReferProtocolEnum referProtocol);

	/**
	 * 帐户划转
	 * 
	 * @param transaction
	 * @param from
	 * @param to
	 * @param orderNo
	 * @param orderType
	 * @return
	 */
	Boolean transferFrom(TblAssetTransaction transaction, TblAssetAccount from, TblAssetAccount to, OrderTypeEnum orderType, String orderNo);

	/**
	 * 减少方
	 * 
	 * @param buildTransaction
	 * @param referProtocol
	 * @return
	 */
	TblAssetTransactionRecord minus(TblAssetTransaction buildTransaction, ReferProtocolEnum referProtocol);

	/**
	 * 增加方
	 * 
	 * @param transaction
	 * @return
	 */
	TblAssetTransactionRecord plus(TblAssetTransaction transaction, ReferProtocolEnum referProtocol);

	/**
	 * @param buildTransaction
	 * @param referProtocol
	 * @param visiable
	 * @return
	 */
	TblAssetTransactionRecord plus(TblAssetTransaction buildTransaction, ReferProtocolEnum referProtocol, Integer visiable);

	/**
	 * @param buildTransaction
	 * @param assetAccount
	 * @param side
	 * @return
	 */
	TblAssetTransactionRecord accountOpertor(TblAssetTransaction buildTransaction, TblAssetAccount assetAccount, TransactionSideEnum side);

	/**
	 * 活动转出
	 * 
	 * @param accountNo
	 * @return
	 */
	TblAssetAccount ownerAssetForUpdate(Long accountNo);

	/**
	 * 大于0的帐户余额
	 * 
	 * @param uid
	 * @param accountNo
	 * @return
	 */
	List<TblAssetAccount> accounts(Long uid, Long[] accountNo);

	/**
	 * 大于0的最早的帐户余额
	 * 
	 * @param uid
	 * @param accountNo
	 * @return
	 */
	TblAssetAccount accountsAtFirst(Long uid, Long[] accountNo);

	/**
	 * 721类资产，更新所有人
	 * 
	 * @param fromAccount
	 * @param toAccount
	 * @return
	 */
	Boolean updateOwner(Long accountNo, Long fromUser, Long toUser);

	/**
	 * 更新余额
	 * 
	 * @param accountNo
	 * @param fromUser
	 * @param beforeBalance
	 * @param afterBalance
	 * @return
	 */
	Boolean updateBalance(Long accountNo, Long fromUser, BigDecimal beforeBalance, BigDecimal afterBalance);

	/**
	 * 查帐户余额
	 * 
	 * @param uid
	 * @param assetId
	 * @return
	 */
	BigDecimal amount(Long uid, Long assetId);

	/**
	 * @param account
	 * @param referProtocol
	 * @param side
	 * @return
	 */
	Boolean accountOpertor(TblAssetAccount account, ReferProtocolEnum referProtocol, TransactionSideEnum side);

	List<TblAssetAccount> infoWithAssetIds(Set<Long> assetId);

	/**
	 * 判断是否已经拥有365礼盒
	 *
	 * @param appUserId
	 * @return
	 */
	boolean hasGift365(Long appUserId);

	/**
	 * 帐户初始化
	 * 
	 * @param assetId
	 * @param userId
	 * @param referProtocol
	 * @return
	 */
	TblAssetAccount initAccount(Long assetId, Long userId, ReferProtocolEnum referProtocol, BigDecimal price);

	TblAssetAccount initAccount(Long assetId, Long userId, ReferProtocolEnum referProtocol, BigDecimal price, Integer visiable);

	/**
	 * 实始化帐户，并设置余额为1,用于721类型的资产初始化
	 * 
	 * @param assetId
	 * @param userId
	 * @param referProtocol
	 * @return
	 */
	TblAssetAccount initAccountOneAmount(Long assetId, Long userId, ReferProtocolEnum referProtocol, BigDecimal amount, BigDecimal price);

	TblAssetAccount initAccountOneAmount(Long assetId, Long userId, ReferProtocolEnum referProtocol, BigDecimal amount, BigDecimal price, Integer visible);

	AssetAccountResponse accountInfoWithId(Long accountId);

	/**
	 * 上架
	 * 
	 * @return
	 */
	Boolean putOnc2cV2(OperateUpRequest operateUpRequest, Long userId);

	/**
	 * 下架
	 * 
	 * @param assetId
	 * @param userId
	 * @return
	 */
	Boolean putOff(Long assetId, Long userId);

	Long queryAccountId(Long assetId, String ownerId);

}
